package com.lagou.service.impl;

import com.lagou.service.EmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @author czq
 * @date 2020/9/15 17:14
 */
@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    /**
     * 发送验证码到邮箱，true成功，false失败
     */
    @Override
    public boolean email(String email, String code) {

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("651854425@qq.com");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("验证码邮件");
        simpleMailMessage.setText("当前邮箱" + email + "的注册验证码是：" + code);
        javaMailSender.send(simpleMailMessage);

        return true;
    }
}
